<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="app" uri="/WEB-INF/tld/app.tld" %>
<%@ taglib prefix="ct" uri="/WEB-INF/tld/commonTag.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/jsp/common/common_header.jsp" %>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<% request.setCharacterEncoding("utf-8"); %>
<% response.setContentType("text/html; charset=utf-8"); %>

<script language="javascript">
	var preFileUpload = true;
	var uploadFileNm;
	function funcDetail(store_code) {
		width = 830;
		height = 730;
	    x = (screen.width) ? (screen.width-width)/2 : 0;
	    y = (screen.height) ? (screen.height-height)/2 : 0;
	    var popUrl = 'popCreditStoreDetailInfo.do?store_code='+store_code;
		window.open(popUrl,'popCreditStoreDetailInfo', 'left=' + x + ',top=' + y + ',width=' + width + ',height=' + height + ',scrollbars=no,status=no,menubar=no');
	}
	
	
	function funUploadFile(obj,fileId,userId,rnum){
		
		if(preFileUpload){
			alert("파일을 선택하세요");
			return;
		}
		var reqDate = $("input[name=deleteDate_"+rnum+"]").val();
		var payProdFee = $("input[name=payProdFee_"+rnum+"]").val();	
		var strStatus =reqDate+" 날짜 데이터를 등록하시겠습니까?";
		if (!confirm(strStatus)) {
			return;
		}			
		
		
		
		var file = $("#"+fileId).val();
        var url = "ajaxRealBankUploadFile.do";   

        $("#uploadForm").attr("action",url);
        $("#userId").val(userId);
        $("#reqDate").val(reqDate);
        $("#payProdFee").val(payProdFee);
        
        var frm = $('#uploadForm');
        var stringData = frm.serialize();
        frm.ajaxSubmit({
            type: "post",
            url: url,
            data: stringData,
	        success : function(data) {
            	if(data.indexOf('success')> -1){
            		alert(" 파일 업로드 성공");	
            		self.location.reload(); 
            	}else{
            		alert(" 파일 업로드 실패");
            	}
	        },
	        error : function(data) {
	            alert("통신에러 입니다. 관리자에게 문의 바랍니다.");
	           
	        }

        });		
	}

    // 검색 버튼 클릭
    function funcSearch() {
        if(checkSpecialRemove(document.form.searchValue.value) == false){
            return false;
        }   

        var searchStRegDt = document.getElementById('searchStRegDt').value.replace(/-/gi,"");
        var searchEdRegDt = document.getElementById('searchEdRegDt').value.replace(/-/gi,"");

        if(searchStRegDt > searchEdRegDt){ 
            alert("등록일의 시작일이 종료일보다 큽니다.");
            return false;
        }
        
        var fm  = document.form;
        $("#page").val(1);
        fm.action = 'realBankList.do';
        fm.submit();
    }
    
    // 엑셀다운
    function funcExcel(excelType){
        $("#excelType").val(excelType);
        document.form.action = 'findShoppingSpcExcel.omp';
        document.form.submit(); 
    }
    
    //////////////////////////////////
    //jQuery datepicker Form set
    ///////////////////////////////// 
    $(function() {
        $("#searchStRegDt").koreadate();
        $("#searchEdRegDt").koreadate();

        var totalCnt = ${realBankList.size()};

        for(var kk=1 ; kk <= totalCnt ; kk++){
        	$("#deleteDate_"+kk).koreadate();	
        	
        }
    });    


    <%-- 파일 유효성 검증 --%>
    function updFileValid(obj){
        
        //파일 유효성 체크
        if(!obj.value){
            if(preFileUpload == false){
                alert("파일을 선택하세요.");
            }
            preFileUpload = true;
            return false;
        }

        var fileNm = obj.value.substring(obj.value.lastIndexOf('\\') + 1, obj.value.lastIndexOf('.')) + "." +  obj.value.substring(obj.value.lastIndexOf('.') + 1, obj.value.length);
        var fileExts = obj.value.substring(obj.value.lastIndexOf('.') + 1, obj.value.length);
        uploadFileNm= fileNm;

        
        
        //파일명 체크
        if(fileExts.toUpperCase().match(/XLS/)==null) {       
            alert("파일 형식을 확인해 주세요.");
            preFileUpload = true;
            return false;
        }
        preFileUpload = false;
        
    }    
    
	function funDeleteData(fileId,userId){
		
		var reqDate = $("input[name=deleteDate_"+fileId+"]").val();
		var flag= "realBank";
		var strStatus =reqDate+" 날짜 데이터를 정말 삭제 하시겠습니까?";
		if (!confirm(strStatus)) {
			return;
		}			
		
		
        var url = "ajaxDeleteData.do";   

        $.ajax({
            type : "POST",
            url : url,
            async : true,
            dataType : "json",
            data : {
            	 reqDate : reqDate
            	,flag : flag
            	,userId : userId
            },
            success : function(data) {
            	if(data == 'success'){
            		alert(reqDate+" 날짜 데이터 삭제 성공");	
            	}else if(data == 'good'){
            		alert(reqDate+" 날짜에 대한 이후 데이터가 있으므로 삭제할수 없습니다. 최근 등록순 부터 삭제 부탁드립니다.");	
            	}else{
            		alert("데이터 삭제 실패");
            	}
            },
            error : function(data) {
                alert("통신에러 입니다. 관리자에게 문의 바랍니다.");
               
            }
        }); 
		
	}	    
    
    function nonHangleFile(fld)
    {
        len = fld.length
        for (t=0;t< len; t++)
        {
            if (escape((fld).substr(t,1)).length > 4)
            {
                alert("한글명 파일을 영문으로 바꿔주세요.");
                return;
            }
        }
    }    
    </script>
</head>
<body>
<div class="con_area">
<form id="form" name="form" action="">
<input type="hidden" id="page" name="page" value="${model.page}"/>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td align="left"><h2 class="tit">은행사 실입금처리  </h2></td>
        <td align="right"><span>이체 관리 > <b>은행사 실입금처리   </b></span></td>
    </tr>
</table>
    <div style="margin-top:7px"/>
        <table cellpadding="0" cellspacing="0" border="0" class="data_table_01">
            <tr>
                <td class="data_01" style='width:100px; text-align:left;'>&nbsp;신청일</td>
                <td class="data_02">
                    <input type='text' id="searchStRegDt" name="searchStRegDt" value="${model.searchStRegDt}" title="YYYY-MM-DD" style="width: 100px;" maxlength="10" readonly/>
                    ~
                    <input type='text' id="searchEdRegDt" name="searchEdRegDt" value="${model.searchEdRegDt}" title="YYYY-MM-DD" style="width: 100px;" maxlength="10" readonly/>
                     &nbsp;
                    <input type="button" class="button_80" value="최근 1주일" onclick="setOrderSearchDateAdminPoC('7day',form.searchStRegDt, form.searchEdRegDt);" />
                    <input type="button" class="button_80" value="최근 1개월" onclick="setOrderSearchDateAdminPoC('1month',form.searchStRegDt, form.searchEdRegDt);" />
                    <input type="button" class="button_80" value="최근 3개월" onclick="setOrderSearchDateAdminPoC('3month',form.searchStRegDt, form.searchEdRegDt);" />
                </td>
            </tr>        
            <tr>
                <td class="data_01" style='width:100px; text-align:left;'>&nbsp;검색조건</td>
                <td class="data_02">
                    <select id="searchType" name='searchValueType'>
                        <option value='' <c:out value="${empty model.searchValueType ? 'selected':''}"/>>전체</option>
                        <option value='01' <c:out value="${model.searchValueType eq '01' ? 'selected':''}"/>>가맹점 명</option>
                        <option value='02' <c:out value="${model.searchValueType eq '02' ? 'selected':''}"/>>사업자 번호</option>
                    </select>
                    <input type="text" id="searchValue" name="searchValue" value="${model.searchValue}" maxlength="50" size="20" onkeydown="if(event.keyCode=='13')funcSearch();"/>
                    <input type='button' class='button_63_01' value='검색' onclick='funcSearch();'>
                </td>
            </tr>
        </table>
</form>        
    <table cellpadding="0" cellspacing="1" border="0" class="data_table_02" style="width:100%;" >
    <colgroup>
        <col width="10%" />
        <col width="15%" />
        <col width="10%" />
        <col width="35%" />
        <col width="15%" />
        <col width="20%" />
    </colgroup>
    <thead>
        <tr>
            <th>번호</th>
            <th>가맹점 명</th>
            <th>요청일</th>
            <th>실입금처리</th>
            <th>수수료</th>
            <th>등록</th>
        </tr>
    </thead>
    <tbody>
<c:if test='${empty realBankList}'>    
    <tr>
        <td colspan="6">
            <span style="padding-top:3px;*padding-top:2px;"><strong>조회된 데이터가 존재하지 않습니다.</strong></span>
        </td>
    </tr>
</c:if>
<c:set var="rnum" value="0"/>
<form id="uploadForm" name="uploadForm" method ="post" enctype="multipart/form-data">
<input type="hidden" name ="userId" id ="userId">
<input type="hidden" name ="payProdFee" id ="payProdFee">

<c:if test='${not empty realBankList}'>
	<c:forEach var="vo" items="${realBankList}" varStatus="status">
<c:set var="rnum" value="${status.count+(model.page-1)*10}"/>	
	    <tr onMouseOver="this.style.background='#FFF9E1'" onMouseOut="this.style.background='#FFFFFF'">
	        <td style="text-align:center;">${rnum}</td>
	        <td style="text-align:center;">${vo.store_name}</td>
	        <td style="text-align:center;">
	        	<input type='text' id="deleteDate_${rnum}" name="deleteDate_${rnum}" value="${model.searchEdRegDt}" title="YYYY-MM-DD" style="width: 100px;" maxlength="10" readonly/>
	        </td>
	        <td style="text-align:center;"><input name="UpFile${rnum}" id="UpFile${rnum}" type="file" class="input" size="40"  maxlength="60" onchange="updFileValid(this); "><br>
										  <font color="red">은행사 입금 xls 파일 선택</font>	        
	        </td>
	        <td style="text-align:center;">
	        	<input type="text" id="payProdFee_${rnum}" name="payProdFee_${rnum}" value="${vo.payProdFee}" maxlength="50" size="15" />        
	        </td>	        
	        <td style="text-align:center;">
	            <input type="button" class="button_28_02" value="등록" style="width:65px;" onclick="funUploadFile(this,'UpFile${rnum}','${vo.user_id}','${rnum}');" />
	           &nbsp;&nbsp;
	            <input type="button" class="button_28_02" value="삭제" style="width:65px;" onclick="funDeleteData('${rnum}','${vo.user_id}');" />
	            
	        </td>
	    </tr>
    </c:forEach>
</c:if>
</form>
    </tbody>
    </table>
    <br>

    
    <div class="paging_area">
        <ul class="paging_lay">
            <li class="paging_01">
                <ct:paging 
                    requestUrl="realBankList.do?searchStRegDt=${model.searchStRegDt}&searchEdRegDt=${model.searchEdRegDt}&searchValueType=${model.searchValueType}&searchValue=${model.searchValue}" 
                    page="${model.page}" 
                    scale="${model.scale}" 
                    blockScale="10" 
                    total="${model.totalCount}"
                    paramPrefix="model" />
            </li>
        </ul>
    </div>


</div>
</body>

